const axios = require("axios");

// 第一个请求的配置
const firstRequestConfig = {
  url: "http://38.12.36.33:2358/submissions",
  method: "POST",
  headers: {
    "content-type": "application/json",
  },
  data: {
    source_code:
      "import java.util.*;\n" +
      "public class Main{\n" +
      "    private static int n;\n" +
      "    private static int N=100010;\n" +
      "    private static int arr[]=new int[N];\n" +
      "    private static int temp[]=new int[N];\n" +
      "    public static void merge_sort(int arr[],int l,int r){\n" +
      "        if(l>=r) return;\n" +
      "        int mid=l+r>>1;\n" +
      "        // 递归左边和右边\n" +
      "        merge_sort(arr,l,mid);merge_sort(arr,mid+1,r);\n" +
      "        // 合并两块\n" +
      "        int k=0,i=l,j=mid+1;\n" +
      "        while(i<=mid&&j<=r) {\n" +
      "            if(arr[i]<arr[j]) temp[k++] =arr[i++];\n" +
      "            else temp[k++] =arr[j++];\n" +
      "        }\n" +
      "        while(i<=mid) temp[k++] =arr[i++];\n" +
      "        while(j<=r) temp[k++]=arr[j++];\n" +
      "        //最后合并到数组里面\n" +
      "        for(i=l,j=0;i<=r;i++,j++) arr[i]=temp[j];\n" +
      "    }\n" +
      "    public static void main(String args[]){\n" +
      "         Scanner sc=new Scanner(System.in);\n" +
      "         n=sc.nextInt();\n" +
      "         for(int i=0;i<n;i++) arr[i]=sc.nextInt();\n" +
      "         merge_sort(arr,0,n-1);\n" +
      '         for(int i=0;i<n;i++) System.out.print(arr[i] + " ");\n' +
      "    }\n" +
      "}",
    language_id: "62",
    number_of_runs: null,
    stdin: "5\n3 1 2 4 5",
    expected_output: "1 2 3 4 5",
    cpu_time_limit: null,
    cpu_extra_time: null,
    wall_time_limit: null,
    memory_limit: null,
    stack_limit: null,
    max_processes_and_or_threads: null,
    enable_per_process_and_thread_time_limit: null,
    enable_per_process_and_thread_memory_limit: null,
    max_file_size: null,
    enable_network: null,
  },
};

// 发送第一个请求
axios(firstRequestConfig)
  .then((response) => {
    const token = response.data.token; // 假设响应中包含 token
    console.log("第一个请求成功，获取到的 token:", token);

    // 等待 1 秒
    setTimeout(() => {
      // 第二个请求的配置
      const secondRequestConfig = {
        url: `http://38.12.36.33:2358/submissions/${token}`,
        method: "GET",
      };

      // 发送第二个请求
      axios(secondRequestConfig)
        .then((secondResponse) => {
          console.log("第二个请求成功，响应数据:", secondResponse.data);
        })
        .catch((secondError) => {
          console.error("第二个请求失败:", secondError);
        });
    }, 2000);
  })
  .catch((error) => {
    console.error("第一个请求失败:", error);
  });
